{{Extend "db/index"}}
{{Block "title"}}{{"SQL命令"|T}} - {{Super}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
{{if Stored.dbName}}<li><a href="{{dbMgrURL "listTable" Stored.dbName}}">{{"数据库"|T}}: {{Stored.dbName}}</a></li>{{end}}
<li class="active">{{"SQL命令"|T}}</li>
{{/Block}}
{{Block "head"}}
<!-- codemirror -->
<link rel="stylesheet" href="__ASSETS__/js/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="__ASSETS__/js/codemirror/theme/night.css">
<script src="__ASSETS__/js/codemirror/lib/codemirror.js"></script>
<script src="__ASSETS__/js/codemirror/addon/mode/loadmode.js"></script>
<style>
.CodeMirror {
    border: 1px solid #ccc;
    min-height:350px
}
</style>
{{/Block}}
{{Block "main"}}
<div class="row">
    <div class="col-md-12">
        {{Include "db/mysql/dbinfo_btn"}}
        {{if Stored.selects}}
        {{range $keyd,$data := Stored.selects}}
        <div class="block-flat">
          {{Include "db/mysql/result" $data.Result}}
          <div class="header">
            <h3>{{"数据"|T}}</h3>
          </div>
          <div class="content">
             <div class="table-responsive">
				<table class="table no-border hover blue">
					<thead class="no-border">
						<tr>{{range $k, $colName := $data.Data.Columns}}
							<th><strong>{{$colName}}</strong></th>
                            {{end}}
						</tr>
					</thead>
					<tbody class="no-border-x" id="tbody-content">
                        {{range $k,$v := $data.Data.Values}}
						<tr>
                            {{range $k, $colName := $data.Data.Columns}}
                            <td>{{(index $v $colName).String}}</td>
                            {{end}}
						</tr>
                        {{end}}
					</tbody>
				</table>
			    </div>
                {{if $data.Explain}}
                <fieldset>
                    <legend class="no-margin-bottom"><a href="javascript:;" onclick="$('#explain-table-{{$keyd}}').toggleClass('hidden');">EXPLAIN</a></legend>
                    <div id="explain-table-{{$keyd}}" class="table-responsive hidden">
				<table class="table no-border hover blue">
					<thead class="no-border">
						<tr>{{range $k, $colName := $data.Explain.Columns}}
							<th><strong>{{$colName}}</strong></th>
                            {{end}}
						</tr>
					</thead>
					<tbody class="no-border-x" id="explain-tbody-content-{{$keyd}}">
                        {{range $k,$v := $data.Explain.Values}}
						<tr>
                            {{range $k, $colName := $data.Explain.Columns}}
                            <td>{{(index $v $colName).String}}</td>
                            {{end}}
						</tr>
                        {{end}}
					</tbody>
				</table>
                    </div>
                </fieldset>
                {{end}}
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
        {{end}}
        {{end}}
        <div class="block-flat no-padding">
          <div class="content no-padding">
              <form class="form-horizontal group-border-dashed" method="POST" action="">
              <div class="form-group">
				<div class="col-sm-12">
                    <textarea name="query" id="query" class="form-control">{{Form "query"}}</textarea>
                </div>
              </div>
              <div class="form-group">
				<div class="col-sm-12">
				    <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-check"></i> {{"执行"|T}}</button>
                    <label for="limit">{{"行数"|T}}: </label><input name="limit" id="limit" type="number" style="width:100px" class="form-control inline" />
                    <label>
                        <input name="error_stops" id="error_stops" type="checkbox" class="icheck" />
                        {{"出错时停止"|T}}
                    </label>
                    <label>
                        <input name="only_errors" id="only_errors" type="checkbox" class="icheck" />
                        {{"只显示错误"|T}}
                    </label>
				</div>
			    </div>
              </form>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
    </div>
</div>
{{/Block}}
{{Block "footer"}}
{{Super}}
<script>
var editor;
CodeMirror.modeURL = "__ASSETS__/js/codemirror/mode/%N/%N.js";
function initCodeMirrorEditor() {
    if(editor)return;
    editor = CodeMirror.fromTextArea($("#query")[0], {
        lineNumbers: true
    });
    editor.setOption('lineWrapping', true);
    //editor.setSize('auto', 'auto');
    editor.setOption("mode", "text/x-{{Form "driver"}}");
    CodeMirror.autoLoadMode(editor, "sql");
}
$(function(){
    initCodeMirrorEditor();
});
</script>
{{/Block}}